package com.jia.interviewPro;

/**
 * 面试题 05.03. 翻转数位
 */
public class Pro0503 {
    public int reverseBits(int num) {
        int maxLen = 0, curLen = 0, preLen = 0;
        int bits = 32;
        while(bits-- > 0) {
            if((num & 1) == 0) {
                curLen -= preLen;
                preLen = curLen + 1;
            }
            curLen++;
            maxLen = Math.max(maxLen, curLen);
            num >>= 1;
        }
        return maxLen;
    }
}
